<template>
<uni-shadow-root class="partials-nearShop-nearShop"><block v-if="receiveData.androidTemplate == ''">
    
    <block v-if="shops.length >0">
      <view class="store_list">
        <view v-for="(item,index) in (shops)" :key="item.index" class="store_item" :data-link="'near_shop_page.html?addShopId='+(item.id)" @click.stop.prevent="tolinkUrl">
          <view class="store_item_left">
            <image class="store_item_logo" mode="widthFix" :src="(item.shopLogo)+'?x-oss-process=style/preview'" v-if="item.shopLogo"></image>
            <image class="store_item_logo" mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/17/11/16/47_265.jpg?x-oss-process=style/preview_120" v-else></image>
          </view>
          <view class="store_item_right">
            <text class="store_item_name">{{item.shopName}}</text>
            <view class="store_item_service">
              <text>服务时间：{{item.serviceStartTime}}:00-{{item.serviceEndTime}}:00</text>
              <text class="distance_text" v-if="item.distance">{{publicFun.toFix(item.distance)}}km</text>
              <text class="distance_text" v-else>未设置</text>
            </view>
            <scroll-view class="tags_content" scroll-x>
              <text v-for="(tags,index) in (item.tagArray)" :key="tags.index" :style="'border:2rpx solid '+(defaultColor)+';color:'+(defaultColor)" class="tags_item" v-if="item.tagArray">{{tags}}</text>
            </scroll-view>
          </view>
        </view>
      </view>
    </block>
    <block v-else>
      <view class="noproduct">
        <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120"></image>
        <text>没有相关店铺</text>
      </view>
    </block>
</block>
<block v-if="receiveData.androidTemplate == 'near_shop_slide'">
    
    <block v-if="shops.length >= "1"">
        <view class="top">
        <view class="topTitle">优质商家</view>
        <view class="topImg"><image mode="aspectFit" src="https://image1.sansancloud.com/xianhua/2019_12/12/13/50/4_17.jpg?x-oss-process=style/preview_120" @click.stop.prevent="tolinkUrl" data-link="near_shops.html"></image></view>
        </view>
        <scroll-view class="near_shop_wrapp" scroll-x="true">
        <block v-for="(item,index) in (shops)" :key="item.index">
            <view class="near_shop_box" :data-id="item.id" :data-index="index" :data-link="'near_shop_page.html?addShopId='+(item.id)" @click.stop.prevent="tolinkUrl">
                <view class="near_shop_banner">
                     <view class="near_shop_banner_img" v-if="item.shopBanner&&item.shopBanner!=''"><image mode="scaleToFill" :src="item.shopBanner"></image></view>
                     <view class="near_shop_banner_img" v-else><image mode="scaleToFill" src="https://image1.sansancloud.com/xianhua/2020_1/2/18/36/36_931.jpg?x-oss-process=style/preview"></image></view>
                     <view class="haoPing">100%好评</view>
                     <view class="near_shop_logo" v-if="item.shopLogo&&item.shopLogo!=''"><image mode="scaleToFill" :src="item.shopLogo"></image></view>
                     <view class="near_shop_logo" v-else><image mode="scaleToFill" src="https://image1.sansancloud.com/xianhua/2020_1/2/18/36/36_931.jpg?x-oss-process=style/preview"></image></view>
                </view>
                <view class="near_shop_name">{{item.shopName}}</view>
                <view class="near_shop_shopTag" v-if="item.shopTag&&item.shopTag!=''">
                  <block v-for="(item,index) in (item.shopTag)" :key="item.index">
                  <view class="near_shop_shopTag_item" v-if="index<=2&&item!=''" :style="'border:2px solid '+(defaultColor)+';'">{{item}}</view>
                  </block>
                </view>
                <view class="near_shop_shopTag" v-else>
                  <view class="near_shop_shopTag_item" :style="'border:2px solid '+(defaultColor)+';'">暂无标签</view>
                </view>
            </view>
        </block> 
        </scroll-view>
    </block>
    <block v-if="shops.length==0">
        <view class="noproduct">
          <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120"></image>
          <text>没有相关店铺</text>
        </view>
    </block>
</block>
<block v-if="receiveData.androidTemplate == 'gongyi_shop_list'">
    
    <block v-if="shops.length >0">
      <view class="store_list">
        <view v-for="(item,index) in (shops)" :key="item.index" class="store_item" :data-link="'near_shop_page.html?addShopId='+(item.id)" @click.stop.prevent="tolinkUrl">
          <view class="i_store_item_head">
              <image class="i_store_item_head_img" mode="widthFix" :src="(item.shopLogo)+'?x-oss-process=style/preview'" v-if="item.shopLogo"></image>
              <image class="i_store_item_head_img" mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/17/11/16/47_265.jpg?x-oss-process=style/preview_120" v-else></image>
          </view>
          <view class="i_store_item_content">
              <text class="i_store_item_name">{{item.shopName}}</text>
              <view class="i_store_item_content_bottom">
                  <view class="i_store_item_content_bottom_item">
                      <text class="i_store_item_content_bottom_item_title">累计捐助价值：</text>
                      <text class="i_store_item_content_bottom_item_value">{{}}元</text>
                  </view>
                  <view class="i_store_item_content_bottom_item">
                      <text class="i_store_item_content_bottom_item_title">优惠买单为老人省：</text>
                      <text class="i_store_item_content_bottom_item_value">{{}}元</text>
                  </view>
              </view>
          </view>
          <view class="i_store_item_nav" :data-item="publicFun.toStringFun(item)" @click.stop.prevent="clickCatch">
              <image src="https://image1.sansancloud.com/xianhua/2019_12/27/17/24/20_148.jpg?x-oss-process=style/preview_120" class="i_store_item_nav_img"></image>
          </view>
        </view>
      </view>
    </block>
    <block v-else>
      <view class="noproduct">
        <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120"></image>
        <text>没有相关店铺</text>
      </view>
    </block>
</block>
<block v-if="receiveData.androidTemplate == 'gongyi_shop_two_list'">
    
    <block v-if="shops.length >0">
      <view class="shop_detail_list">
        <view v-for="(item,index) in (shops)" :key="item.index" class="shop_detail_item">
          <view class="shop_detail_item_short_info" :data-link="'near_shop_page.html?addShopId='+(item.id)" @click.stop.prevent="tolinkUrl">
              <view class="shop_detail_item_short_info_icon">
                  <image class="shop_detail_item_short_info_img" mode="widthFix" :src="(item.shopLogo)+'?x-oss-process=style/preview'" v-if="item.shopLogo"></image>
                  <image class="shop_detail_item_short_info_img" mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/17/11/16/47_265.jpg?x-oss-process=style/preview_120" v-else></image>
              </view>
              <view class="shop_detail_item_short_info_content">
                  <view class="shop_detail_item_short_info_content_top">
                      <text class="shop_name">{{item.shopName}}</text>
                      <text class="shop_distance" v-if="'item.distance'">距{{publicFun.toFix(item.distance||0)}}km</text>
                      <text class="shop_distance" v-else>未设置</text>
                  </view>
                  <view class="shop_detail_item_short_info_content_bottom">
                      <scroll-view class="tags_content" scroll-x>
                        <view v-for="(tags,index) in (item.tagArray)" :key="tags.index" :style="'border:2rpx solid '+(defaultColor)+';color:'+(defaultColor)" class="tags_item" v-if="item.tagArray">{{tags}}</view>
                      </scroll-view>
                  </view>
              </view>
          </view>
          <scroll-view class="shop_detail_product_list" scroll-x v-if="item.items&&item.items.length!=0">
              <view v-for="(productItem,index) in (item.items)" :key="productItem.index" class="shop_detail_product_item" :data-info="publicFun.toStringFun(productItem)" @click.stop.prevent="toProlinkUrl">
                  <view class="shop_detail_product_item_icon">
                      <image :src="productItem.imagePath" class="shop_detail_product_item_img"></image>
                  </view>
                  <text class="product_name">{{productItem.name}}</text>
                  <text class="product_price">￥{{productItem.price}}</text>
              </view>
          </scroll-view>
          <text v-else class="no_shop_product_list">该店铺暂无产品~</text>
        </view>
      </view>
    </block>
    <block v-else>
      <view class="noproduct">
        <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120"></image>
        <text>没有相关店铺</text>
      </view>
    </block>
</block></uni-shadow-root>
</template>
<wxs src="../../public/publicFun.wxs" module="publicFun"></wxs>
<script>

global['__wxRoute'] = 'partials/nearShop/nearShop'
const app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Component({
  properties: {
    receiveData: {
      type: JSON,
      value: 'default value',
    }
  },
  data: {
    someData: {},
    page:"1",
    shops:[],
    journey:[],//公里数
  },
  ready:function(){
    this.getData();
    if (app.globalData.setting.platformSetting.defaultColor && app.globalData.setting.platformSetting.defaultColor !=""){
      app.globalData.consoleFun("=====nearShop组件-defaultColor=====",[this.data.receiveData,app.globalData.setting.platformSetting.defaultColor])
      // 有默认色
      this.setData({
        defaultColor: app.globalData.setting.platformSetting.defaultColor
      })
    }
    else{
      // 没有默认色
      this.setData({
        defaultColor: app.globalData.setting.platformSetting.defaultColor
      })
    }
  },
  methods: {
      toProlinkUrl: function (e) {
        app.globalData.consoleFun("=====productList组件-tolinkUrl=====",[e.currentTarget.dataset.info])
        let productData = e.currentTarget.dataset.info;
        if(productData){
            productData=JSON.parse(productData)
        }
        let link="";
        if (productData.productType==6){
          link = "ticket_detail.html?productId=" + productData.id; 
        }else{
          link = "product_detail.html?productId=" + productData.id; 
        }
        app.globalData.linkEvent(link);
      },
      // 定位
      clickCatch: function (e) {
        console.log("===clickCatch===",e);
        let itemData=e.currentTarget.dataset.item;
        if(itemData&&itemData!=""){
            itemData=JSON.parse(itemData)
        }
        let latitude = itemData.latitude;
        let longitude = itemData.longitude;
        let name = itemData.shopName;
        let address = itemData.shopLocation;
        wx.openLocation({
          latitude: latitude,
          longitude: longitude,
          scale: 12,
          name: name,
          address: address
        });
      },
    tolinkUrl: function (e) {
      app.globalData.consoleFun("=====nearShop组件-link=====",[e.currentTarget.dataset.link])
      let linkUrl = e.currentTarget.dataset.link
      app.globalData.linkEvent(linkUrl)
    },
    getData:function(){
      let that = this;
      let shopName = app.globalData.setting.platformSetting.defaultShopBean.account.shopName
      wx.getLocation({
        type: 'gcj02',
        success: function (res) {
          let latitude = res.latitude
          let longitude = res.longitude
          app.globalData.consoleFun("=====nearShop组件-getLocation=====",[longitude,latitude,that.data.page])
          let pageParam = { 
            "longitude": longitude,
            "latitude": latitude,
            "page": that.data.page,
            "pageObjectType":that.data.receiveData.pageObjectType||0,
            "pageObjectId":that.data.receiveData.pageObjectId||0
          }
          if(that.data.receiveData.jsonData.shopTypeId){
              pageParam=Object.assign({},pageParam,{ "shopTypeId":that.data.receiveData.jsonData.shopTypeId})
          }
          app.globalData.consoleFun("=====nearShop组件-pageParam=====",[pageParam])
          let customIndex = app.globalData.AddClientUrl("/more_near_shops.html", pageParam, 'get', 1)
          app.globalData.showToastLoading('loading', true)
          wx.request({
            url: customIndex.url,
            header: app.globalData.header,
            method: 'GET',
            success: function (res) {
              that.setData({
                shops: res.data.relateObj.result
              })
              app.globalData.consoleFun("=====nearShop组件-success=====",[res,res.data.relateObj.result])
              // 店铺标签是带【】的字符串需要改
              let shops = res.data.relateObj.result;
              let tagArray=[];
              for (let j = 0; j < shops.length; j++) {
                // 获取公里数
                shops[j].distance = app.globalData.getDistance(latitude, longitude, shops[j].latitude, shops[j].longitude)
                if (shops[j].shopTag) {
                  tagArray = shops[j].shopTag.slice(1, -1).split("][")
                  shops[j].tagArray = tagArray;
                }
              }
              that.setData({shops: shops})
              if (res.data.errcode < 0) {
                app.globalData.consoleFun("=====nearShop组件-fail=====",[res.data.errMsg])
              }
              else {
                wx.hideLoading()
              }
            },
            fail: function (res) {
              wx.hideLoading()
              app.globalData.loadFail()
            }
          })
        }
      })
    },
  },
})
export default global['__wxComponents']['partials/nearShop/nearShop']
</script>
<style platform="mp-weixin">
@import 'near_shop_slide/near_shop_slide.css';/* 引入滑动的附近店铺列表 */
@import 'gongyi_near_shop/index.css';/* 引入滑动的附近店铺列表 */
@import 'gongyi_near_shop_two/index.css';/* 引入滑动的附近店铺列表 */
.tags_content::-webkit-scrollbar{
    width: 0;
    height: 0;
    color: transparent;
    display:none ;
}
/*没有相关商品  */
.noproduct{
  width: 100%;
  height: 200rpx;
  text-align: center;
  display: flex;
  flex-direction: column;
}
.noproduct image{
  width: 150rpx;
  height: 150rpx;
  margin: 0 auto;
}
.noproduct text{
  font-size: 30rpx;
}
.store_list{
  display: flex;
  flex-direction: column;
  overflow: hidden
}
.store_item{
  display: flex;
  flex-direction: row;
  padding: 20rpx;
}
.store_item_left{
  margin-right: 20rpx;
}
.store_item_logo{
  width:150rpx;
  height: 150rpx; 
  border-radius:10rpx;
}
.store_item_right{
  display: flex;
  flex-direction: column;
  width: 75%;
}
.store_item_name{
  font-size: 30rpx;
  color: #333;
  margin-bottom: 20rpx;
}
.store_item_service{
  font-size: 22rpx;
  color: #999;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
.tags_content{
  display: flex;
  flex-direction: row;
  align-items: center;
  overflow-x:hidden;
  width:100%;
  height:50rpx;
  white-space: nowrap;
}
.tags_item{
  border: 2rpx solid #eee;
  padding: 2rpx 12rpx;
  font-size: 22rpx;
  color: #888;
  margin-right: 10rpx;
  border-radius: 4rpx;
  white-space:nowrap;
  box-sizing: content-box;
  display:inline-block;
}
</style>